# _*_ encoding: utf-8 _*_
import matplotlib.pyplot as plt


def load_csv(filename, parse, header=False):
    fp = open(filename, "r")
    if header:
        fp.readline()
    dataset = []
    for line in fp.readlines():
        dataset.append(parse(line))
    return dataset


def parse_line(line):
    return map(float, line.strip().split(','))


def plotindex(dataset):
    X = []
    index = []
    porprotion = []
    for item in dataset:
        X.append(item[0])
        porprotion.append(item[1])
        index.append(item[2])

    plt.plot(X, index, label=u'index')
    plt.plot(X, porprotion, label="proportion", color='red')
    plt.legend(loc="upper left")
    plt.show()


def main(options=None):
    # filename = "../../data/hangzhou08.csv"
    # filename = "../../data/result/10221507-10232026.csv"
    # filename="../../data/1030/10302243.result.csv"
    filename = "../../data/1101/index-calculate.res.csv"
    # filename = "../../data/1101/index-calculate-1.res.csv"
    dataset = load_csv(filename, parse_line)
    plotindex(dataset)

if __name__ == '__main__':
    main()
